package LeetCode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName interview
 * @Description: TODO
 * @date ${DAT}14:44
 */
public class LeetCode129 {
    public static class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
  // 怕是还是要回溯法
  public int sumNumbers(TreeNode root) {
      return helper(root, 0);
  }

    public int helper(TreeNode root, int i){
        if (root == null){
            return 0;
        }
        int temp = i * 10 + root.val;
        if (root.right == null && root.left == null){
            return temp;
        }
        return helper(root.left,temp) + helper(root.right,temp);
    }



    public static void main(String[] args) {
        TreeNode node = new TreeNode(1);
        node.left = new TreeNode(0);
//        node.right = new TreeNode(3);
        System.out.println(new LeetCode129().sumNumbers(node));
    }
}
